package leecode

type MyCalendarTwo struct {
	events     []Event731
	sameEvents []Event731
}

type Event731 struct {
	start int
	end   int
}

func Constructor731() MyCalendarTwo {
	return MyCalendarTwo{}
}

func (this *MyCalendarTwo) Book(start int, end int) bool {
	//先判断是否出现三重时间
	for _, same := range this.sameEvents {
		if same.start < end && same.end > start {
			return false
		}
	}
	for _, event := range this.events {
		//如果出现了一次时间间隔
		if event.start < end && event.end > start {
			this.sameEvents = append(this.sameEvents, struct {
				start int
				end   int
			}{start: max(start, event.start), end: min(end, event.end)})
		}
	}
	this.events = append(this.events, struct {
		start int
		end   int
	}{start: start, end: end})
	return true
}
